package com.sad.controller.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

import com.sad.model.Orderback;
import com.sad.service.IService;
import com.sad.service.ServiceManager;
import com.sad.util.G;

public class ExpressformAction extends BaseAction {

	@Override
	protected String getViewPackage() {
		return "lease/";
	}

	public void handle(HttpServletRequest req, HttpServletResponse resp) {
		Map<String, Object> parms = new HashMap<String, Object>();
		this.setParams(req, parms);

		String action = StringUtils.defaultString(req.getParameter("action"), "findbyid");

		parms.put("wishid", req.getParameter("wishid"));
		parms.put("userid", req.getParameter("userid"));
		parms.put("orderid", req.getParameter("orderid"));

		if ("findbyid".equals(action)) {
			findById(req, resp, parms);
		} else if ("create".equals(action)) {
			create(req, resp, parms);
		}

	}

	/**
	 * 
	 * @param req
	 * @param resp
	 * @param parms
	 */
	protected void findById(HttpServletRequest req, HttpServletResponse resp,
			Map<String, Object> parms) {
		IService s = ServiceManager.allo((String) parms.get(G.K.pageid));

		Orderback orderback = (Orderback) s.findById(parms);

		req.setAttribute("orderback", orderback);

		new Render().renderJsp(req, resp);

	}

	protected void create(HttpServletRequest req, HttpServletResponse resp,
			Map<String, Object> parms) {

		parms.put("orderid", req.getParameter("orderid"));
		parms.put("userid", req.getParameter("userid"));
		parms.put("company", req.getParameter("company"));
		parms.put("excode", req.getParameter("excode"));
		parms.put("courier", req.getParameter("courier"));
		parms.put("exmobile", req.getParameter("exmobile"));

		IService s = ServiceManager.allo((String) parms.get(G.K.pageid));

		String json = s.create(parms);

		new Render().renderJson(resp, json);
	}

}
